home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / texinfo / elisp / texinfo.el < prev    next >
Lisp/Scheme  |  1992-08-27  |  26KB  |  725 lines

  1. ;;;; texinfo.el
  2.  
  3. ;;; Major mode for editing Texinfo files.
  4.  
  5. ;;; Version 2.12   18 August 1992
  6. ;;; Robert J. Chassell          
  7. ;;; Please send bug reports to:  bob@gnu.ai.mit.edu
  8.  
  9. ;; Copyright (C) 1985, '88, '89, '90, '91, '92 Free Software Foundation, Inc.
  10.  
  11.  
  12. ;;; This file is part of GNU Emacs.
  13.  
  14. ;; GNU Emacs is free software; you can redistribute it and/or modify
  15. ;; it under the terms of the GNU General Public License as published by
  16. ;; the Free Software Foundation; either version 1, or (at your option)
  17. ;; any later version.
  18.  
  19. ;; GNU Emacs is distributed in the hope that it will be useful,
  20. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22. ;; GNU General Public License for more details.
  23.  
  24. ;; You should have received a copy of the GNU General Public License
  25. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  26. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  27.  
  28.  
  29. ;;; Autoloads
  30.  
  31. (autoload 'texinfo-format-region
  32.           "texinfmt"
  33.   "Convert the current region of the Texinfo file to Info format.
  34. This lets you see what that part of the file will look like in Info.
  35. The command is bound to \\[texinfo-format-region].  The text that is
  36. converted to Info is stored in a temporary buffer."
  37.           t nil)
  38.  
  39. (autoload 'texinfo-format-buffer
  40.           "texinfmt"
  41.   "Process the current buffer as texinfo code, into an Info file.
  42. The Info file output is generated in a buffer visiting the Info file
  43. names specified in the @setfilename command.
  44.  
  45. Non-nil argument (prefix, if interactive) means don't make tag table
  46. and don't split the file if large.  You can use Info-tagify and
  47. Info-split to do these manually."
  48.           t nil)
  49.  
  50. (autoload 'makeinfo-region
  51.           "makeinfo"
  52.   "Make Info file from region of current Texinfo source file.
  53.  
  54. The \\[next-error] command can be used to move to the next error \(if
  55. any are found\)."
  56.           t nil)
  57.  
  58. (autoload 'makeinfo-buffer
  59.           "makeinfo"
  60.   "Make Info file from current buffer.
  61.  
  62. The \\[next-error] command can be used to move to the next error 
  63. \(if any are found\)."
  64.           t nil)
  65.  
  66. (autoload 'kill-compilation
  67.           "compile"
  68.   "Kill the process made by the \\[compile] command."
  69.           t nil)
  70.  
  71. (autoload 'makeinfo-recenter-compilation-buffer
  72.           "makeinfo"
  73.   "Redisplay *compilation* buffer so that most recent output can be seen.
  74. The last line of the buffer is displayed on
  75. line LINE of the window, or centered if LINE is nil."
  76.           t nil)
  77.  
  78. (autoload 'texinfo-tex-region
  79.           "texnfo-tex"
  80.   "Run tex on the current region. 
  81.  
  82. A temporary file is written in the default directory, and tex is run
  83. in that directory.  The first line of the file is copied to the
  84. temporary file; and if the buffer has a header, it is written to the
  85. temporary file before the region itself.  The buffer's header is all
  86. lines between the strings defined by texinfo-start-of-header and
  87. texinfo-end-of-header inclusive.  The header must start in the first 100
  88. lines.  The value of texinfo-tex-trailer is appended to the temporary file
  89. after the region."
  90.           t nil)
  91.  
  92. (autoload 'texinfo-tex-buffer
  93.           "texnfo-tex"
  94.   "Run TeX on current buffer.
  95. After running TeX the first time, you may have to run \\[texinfo-texindex]
  96. and then \\[texinfo-tex-buffer] again."
  97.           t nil)
  98.  
  99. (autoload 'texinfo-kill-tex-job
  100.           "texnfo-tex"
  101.   "Kill the currently running TeX job."
  102.           t nil)
  103.  
  104. (autoload 'texinfo-recenter-tex-output-buffer
  105.           "texnfo-tex"
  106.   "Redisplay buffer of TeX job output so that most recent output can be seen.
  107. The last line of the buffer is displayed on
  108. line LINE of the window, or centered if LINE is nil."
  109.           t nil)
  110.  
  111. (autoload 'texinfo-delete-from-tex-print-queue
  112.           "texnfo-tex"
  113.   "Delete job from the line printer spooling queue.
  114. You are prompted for the job number (shown by a previous
  115. \\[texinfo-show-tex-print-queue] command."
  116.           t nil)
  117.  
  118. (autoload 'texinfo-show-tex-print-queue
  119.           "texnfo-tex"
  120.   "Show the print queue that \\[texinfo-tex-print] put your job on.
  121. Runs the shell command defined by texinfo-show-tex-queue-command."
  122.           t nil)
  123.  
  124. (autoload 'texinfo-tex-print
  125.           "texnfo-tex"
  126.   "Print .dvi file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  127. Runs the shell command defined by texinfo-tex-dvi-print-command."
  128.           t nil)
  129.  
  130. (autoload 'texinfo-texindex
  131.           "texnfo-tex"
  132.   "Run texindex on unsorted index files.
  133. The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  134. Runs the shell command defined by texinfo-texindex-command."
  135.           t nil)
  136.  
  137. (autoload 'texinfo-make-menu
  138.           "texnfo-upd"
  139.   "Without any prefix argument, make or update a menu.
  140. Make the menu for the section enclosing the node found following point.
  141.  
  142. Non-nil argument (prefix, if interactive) means make or update menus
  143. for nodes within or part of the marked region.
  144.  
  145. Whenever a menu exists, and is being updated, the descriptions that
  146. are associated with node names in the pre-existing menu are
  147. incorporated into the new menu.  Otherwise, the nodes' section titles
  148. are inserted as descriptions."
  149.           t nil)
  150.  
  151. (autoload 'texinfo-update-node
  152.           "texnfo-upd"
  153.   "Without any prefix argument, update the node in which point is located.
  154. Non-nil argument (prefix, if interactive) means update the nodes in the
  155. marked region.
  156.  
  157. The functions for creating or updating nodes and menus, and their
  158. keybindings, are:
  159.  
  160.     texinfo-update-node (&optional region-p)    \\[texinfo-update-node]
  161.     texinfo-every-node-update ()                \\[texinfo-every-node-update]
  162.     texinfo-sequential-node-update (&optional region-p)
  163.  
  164.     texinfo-make-menu (&optional region-p)      \\[texinfo-make-menu]
  165.     texinfo-all-menus-update ()                 \\[texinfo-all-menus-update]
  166.     texinfo-master-menu ()
  167.  
  168.     texinfo-indent-menu-description (column &optional region-p)
  169.  
  170. The `texinfo-column-for-description' variable specifies the column to
  171. which menu descriptions are indented. Its default value is 24."
  172.           t nil)
  173.  
  174. (autoload 'texinfo-every-node-update
  175.           "texnfo-upd"
  176.   "Update every node in a Texinfo file."
  177.           t nil)
  178.  
  179. (autoload 'texinfo-all-menus-update
  180.           "texnfo-upd"
  181.   "Update every regular menu in a Texinfo file.
  182. Remove pre-existing master menu, if there is one.
  183.  
  184. If called with a non-nil argument, this function first updates all the
  185. nodes in the buffer before updating the menus."
  186.           t nil)
  187.  
  188. (autoload 'texinfo-master-menu
  189.           "texnfo-upd"
  190.   "Make a master menu for a whole Texinfo file.
  191. Non-nil argument (prefix, if interactive) means first update all
  192. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  193.  
  194. This function creates a master menu that follows the top node.  The
  195. master menu includes every entry from all the other menus.  It
  196. replaces any existing ordinary menu that follows the top node.
  197.  
  198. If called with a non-nil argument, this function first updates all the
  199. menus in the buffer (incorporating descriptions from pre-existing
  200. menus) before it constructs the master menu.
  201.  
  202. The function removes the detailed part of an already existing master
  203. menu.  This action depends on the pre-exisitng master menu using the
  204. standard `texinfo-master-menu-header'.
  205.  
  206. The master menu has the following format, which is adapted from the
  207. recommendation in the Texinfo Manual:
  208.  
  209.    * The first part contains the major nodes in the Texinfo file: the
  210.      nodes for the chapters, chapter-like sections, and the major
  211.      appendices.  This includes the indices, so long as they are in
  212.      chapter-like sections, such as unnumbered sections.
  213.  
  214.    * The second and subsequent parts contain a listing of the other,
  215.      lower level menus, in order.  This way, an inquirer can go
  216.      directly to a particular node if he or she is searching for
  217.      specific information.
  218.  
  219. Each of the menus in the detailed node listing is introduced by the
  220. title of the section containing the menu."
  221.           t nil)
  222.  
  223. (autoload 'texinfo-indent-menu-description
  224.           "texnfo-upd"
  225.   "Indent every description in menu following point to COLUMN.  
  226. Non-nil argument (prefix, if interactive) means indent every
  227. description in every menu in the region.  Does not indent second and
  228. subsequent lines of a multi-line description."
  229.           t nil)
  230.  
  231. (autoload 'texinfo-sequential-node-update
  232.           "texnfo-upd"
  233.   "Update one node (or many) in a Texinfo file with sequential pointers.
  234.  
  235. This function causes the `Next' or `Previous' pointer to point to the
  236. immediately preceding or following node, even if it is at a higher or
  237. lower hierarchical level in the document.  Continually pressing `n' or
  238. `p' takes you straight through the file.
  239.  
  240. Without any prefix argument, update the node in which point is located.
  241. Non-nil argument (prefix, if interactive) means update the nodes in the
  242. marked region.
  243.  
  244. This command makes it awkward to navigate among sections and
  245. subsections; it should be used only for those documents that are meant
  246. to be read like a novel rather than a reference, and for which the
  247. Info `g*' command is inadequate."
  248.           t nil)
  249.  
  250. (autoload 'texinfo-insert-node-lines
  251.           "texnfo-upd"
  252.   "Insert missing `@node' lines in region of Texinfo file.
  253. Non-nil argument (prefix, if interactive) means also to insert the
  254. section titles as node names; and also to insert the section titles as
  255. node names in pre-existing @node lines that lack names."
  256.           t nil)
  257.  
  258. (autoload 'texinfo-start-menu-description
  259.           "texnfo-upd"
  260.   "In this menu entry, insert the node's section title as a description. 
  261. Position point at beginning of description ready for editing.
  262. Do not insert a title if the line contains an existing description.
  263.  
  264. You will need to edit the inserted text since a useful description
  265. complements the node name rather than repeats it as a title does."
  266.           t nil)
  267.  
  268. (autoload 'texinfo-multiple-files-update
  269.           "texnfo-upd"
  270.   "Update first node pointers in each file included in OUTER-FILE;
  271. create or update main menu in the outer file that refers to such nodes. 
  272. This does not create or update menus or pointers within the included files.
  273.  
  274. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  275. insert a master menu in OUTER-FILE.  This does not create or update
  276. menus or pointers within the included files.
  277.  
  278. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  279. interactive), update all the menus and all the `Next', `Previous', and
  280. `Up' pointers of all the files included in OUTER-FILE before inserting
  281. a master menu in OUTER-FILE.
  282.  
  283. The command also updates the `Top' level node pointers of OUTER-FILE.
  284.  
  285. Notes: 
  286.  
  287.   * this command does NOT save any files--you must save the
  288.     outer file and any modified, included files.
  289.  
  290.   * except for the `Top' node, this command does NOT handle any
  291.     pre-existing nodes in the outer file; hence, indices must be
  292.     enclosed in an included file.
  293.  
  294. Requirements:
  295.  
  296.   * each of the included files must contain exactly one highest
  297.     hierarchical level node, 
  298.   * this highest node must be the first node in the included file,
  299.   * each highest hierarchical level node must be of the same type.
  300.  
  301. Thus, normally, each included file contains one, and only one,
  302. chapter."
  303.           t nil)
  304.  
  305.  
  306. ;;; Syntax table
  307.  
  308. (defvar texinfo-mode-syntax-table nil)
  309.  
  310. (if texinfo-mode-syntax-table
  311.     nil
  312.   (setq texinfo-mode-syntax-table (make-syntax-table))
  313.   (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
  314.   (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
  315.   (modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
  316.   (modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
  317.   (modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
  318.   (modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
  319.   (modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
  320.   (modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
  321.   (modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
  322.  
  323.  
  324. ;;; Keybindings
  325. (defvar texinfo-mode-map nil)
  326.  
  327. ;;; Keys common both to Texinfo mode and to TeX shell.
  328.  
  329. (defun texinfo-define-common-keys (keymap)
  330.   "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  331.   (define-key keymap "\C-c\C-t\C-k"    'texinfo-kill-tex-job)
  332.   (define-key keymap "\C-c\C-t\C-x"    'texinfo-quit-tex-job)
  333.   (define-key keymap "\C-c\C-t\C-l"    'texinfo-recenter-tex-output-buffer)
  334.   (define-key keymap "\C-c\C-t\C-d"    'texinfo-delete-from-tex-print-queue)
  335.   (define-key keymap "\C-c\C-t\C-q"    'texinfo-show-tex-print-queue)
  336.   (define-key keymap "\C-c\C-t\C-p"    'texinfo-tex-print)
  337.   (define-key keymap "\C-c\C-t\C-i"    'texinfo-texindex)
  338.  
  339.   (define-key keymap "\C-c\C-t\C-r"    'texinfo-tex-region)
  340.   (define-key keymap "\C-c\C-t\C-b"    'texinfo-tex-buffer))
  341.  
  342. ;; Mode documentation displays commands in reverse order 
  343. ;; from how they are listed in the texinfo-mode-map.
  344.  
  345. (if texinfo-mode-map
  346.     nil
  347.   (setq texinfo-mode-map (make-sparse-keymap))
  348.  
  349.   ;; bindings for `texnfo-tex.el'
  350.   (texinfo-define-common-keys texinfo-mode-map)
  351.  
  352.   ;; bindings for `texinfmt.el'
  353.   (define-key texinfo-mode-map "\C-c\C-e\C-r"    'texinfo-format-region)
  354.   (define-key texinfo-mode-map "\C-c\C-e\C-b"    'texinfo-format-buffer)
  355.  
  356.   ;; bindings for `makeinfo.el'
  357.   (define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
  358.   (define-key texinfo-mode-map "\C-c\C-m\C-l" 
  359.     'makeinfo-recenter-compilation-buffer)
  360.   (define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
  361.   (define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
  362.  
  363.   ;; bindings for updating nodes and menus
  364.  
  365.   (define-key texinfo-mode-map "\C-c\C-um"   'texinfo-master-menu)
  366.  
  367.   (define-key texinfo-mode-map "\C-c\C-u\C-m"   'texinfo-make-menu)
  368.   (define-key texinfo-mode-map "\C-c\C-u\C-n"   'texinfo-update-node)
  369.   (define-key texinfo-mode-map "\C-c\C-u\C-e"   'texinfo-every-node-update)
  370.   (define-key texinfo-mode-map "\C-c\C-u\C-a"   'texinfo-all-menus-update)
  371.  
  372.   (define-key texinfo-mode-map "\C-c\C-s"     'texinfo-show-structure)
  373.  
  374.   (define-key texinfo-mode-map "\C-c\C-c}"    'up-list)
  375.   (define-key texinfo-mode-map "\C-c\C-c]"    'up-list) ; easier to type
  376.   (define-key texinfo-mode-map "\C-c\C-c{"    'texinfo-insert-braces)
  377.  
  378.   ;; bindings for inserting strings
  379.  
  380.   (define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
  381.  
  382.   (define-key texinfo-mode-map "\C-c\C-cv"    'texinfo-insert-@var)
  383.   (define-key texinfo-mode-map "\C-c\C-ct"    'texinfo-insert-@table)
  384.   (define-key texinfo-mode-map "\C-c\C-cs"    'texinfo-insert-@samp)
  385.   (define-key texinfo-mode-map "\C-c\C-co"    'texinfo-insert-@noindent)
  386.   (define-key texinfo-mode-map "\C-c\C-cn"    'texinfo-insert-@node)
  387.   (define-key texinfo-mode-map "\C-c\C-ck"    'texinfo-insert-@kbd)
  388.   (define-key texinfo-mode-map "\C-c\C-ci"    'texinfo-insert-@item)
  389.   (define-key texinfo-mode-map "\C-c\C-cf"    'texinfo-insert-@file)
  390.   (define-key texinfo-mode-map "\C-c\C-cx"    'texinfo-insert-@example)
  391.   (define-key texinfo-mode-map "\C-c\C-ce"    'texinfo-insert-@end)
  392.   (define-key texinfo-mode-map "\C-c\C-cd"    'texinfo-insert-@dfn)
  393.   (define-key texinfo-mode-map "\C-c\C-cc"    'texinfo-insert-@code))
  394.  
  395.  
  396. ;;; Texinfo mode
  397.  
  398. (defvar texinfo-chapter-level-regexp 
  399.   "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
  400.   "*Regexp matching chapter-level headings (but not the top node).")
  401.  
  402. (defun texinfo-mode ()
  403.   "Major mode for editing Texinfo files.
  404.  
  405.   It has these extra commands:
  406. \\{texinfo-mode-map}
  407.  
  408.   These are files that are used as input for TeX to make printed manuals
  409. and also to be turned into Info files by \\[texinfo-format-buffer] or
  410. `makeinfo'.  These files must be written in a very restricted and
  411. modified version of TeX input format.
  412.  
  413.   Editing commands are like text-mode except that the syntax table is
  414. set up so expression commands skip Texinfo bracket groups.  To see
  415. what the Info version of a region of the Texinfo file will look like,
  416. use \\[texinfo-format-region].  This command runs Info on the current region
  417. of the Texinfo file and formats it properly.
  418.  
  419.   You can show the structure of a Texinfo file with \\[texinfo-show-structure].
  420. This command shows the structure of a Texinfo file by listing the
  421. lines with the @-sign commands for @chapter, @section, and the like.
  422. These lines are displayed in another window called the *Occur* window.
  423. In that window, you can position the cursor over one of the lines and
  424. use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
  425. in the Texinfo file.
  426.  
  427.   In addition, Texinfo mode provides commands that insert various
  428. frequently used @-sign commands into the buffer.  You can use these
  429. commands to save keystrokes.  And you can insert balanced braces with
  430. \\[texinfo-insert-braces] and later use the command \\[up-list] to
  431. move forward past the closing brace.
  432.  
  433. Also, Texinfo mode provides functions for automatically creating or
  434. updating menus and node pointers.  These functions
  435.  
  436.   * insert the `Next', `Previous' and `Up' pointers of a node,
  437.   * insert or update the menu for a section, and
  438.   * create a master menu for a Texinfo source file.
  439.  
  440. Here are the functions:
  441.  
  442.     texinfo-update-node                \\[texinfo-update-node]
  443.     texinfo-every-node-update          \\[texinfo-every-node-update]
  444.     texinfo-sequential-node-update 
  445.  
  446.     texinfo-make-menu                  \\[texinfo-make-menu]
  447.     texinfo-all-menus-update           \\[texinfo-all-menus-update]
  448.     texinfo-master-menu
  449.  
  450.     texinfo-indent-menu-description (column &optional region-p)
  451.  
  452. The `texinfo-column-for-description' variable specifies the column to
  453. which menu descriptions are indented. 
  454.  
  455. Passed an argument (a prefix argument, if interactive), the
  456. `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
  457. in the region.
  458.  
  459. To use the updating commands, you must structure your Texinfo file
  460. hierarchically, such that each `@node' line, with the exception of the
  461. Top node, is accompanied by some kind of section line, such as an
  462. `@chapter' or `@section' line.
  463.  
  464. If the file has a `top' node, it must be called `top' or `Top' and
  465. be the first node in the file.
  466.  
  467. Entering Texinfo mode calls the value of text-mode-hook, and then the
  468. value of texinfo-mode-hook."
  469.   (interactive)
  470.   (text-mode)
  471.   (setq mode-name "Texinfo")
  472.   (setq major-mode 'texinfo-mode)
  473.   (use-local-map texinfo-mode-map)
  474.   (set-syntax-table texinfo-mode-syntax-table)
  475.   (make-local-variable 'page-delimiter)
  476.   (setq page-delimiter 
  477.         (concat 
  478.          "^@node [ \t]*[Tt]op\\|^@\\(" 
  479.          texinfo-chapter-level-regexp 
  480.          "\\)"))
  481.   (make-local-variable 'require-final-newline)
  482.   (setq require-final-newline t)
  483.   (make-local-variable 'indent-tabs-mode)
  484.   (setq indent-tabs-mode nil)
  485.   (make-local-variable 'paragraph-separate)
  486.   (setq paragraph-separate (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
  487.   (make-local-variable 'paragraph-start)
  488.   (setq paragraph-start (concat "^\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
  489.   (make-local-variable 'fill-column)
  490.   (setq fill-column 72)
  491.   (make-local-variable 'comment-start)
  492.   (setq comment-start "@c ")
  493.   (make-local-variable 'comment-start-skip)
  494.   (setq comment-start-skip "@c +")
  495.   (make-local-variable 'words-include-escapes)
  496.   (setq words-include-escapes t)
  497.   (make-local-variable 'texinfo-start-of-header)
  498.   (setq texinfo-start-of-header "%**start")
  499.   (make-local-variable 'texinfo-end-of-header)
  500.   (setq texinfo-end-of-header "%**end")
  501.   (run-hooks 'text-mode-hook 'texinfo-mode-hook))
  502.  
  503.  
  504. ;;; Define start and end of header expressions 
  505.  
  506. ;; The start-of-header and end-of-header expressions are defined here
  507. ;; since they used by both by `texinfmt.el' and by `texnfo-tex.el',
  508. ;; only one of which is likely to be loaded at one time.
  509.  
  510. (defvar texinfo-start-of-header "%**start"
  511.   "String to mark start of header for texinfo-tex-region.")
  512.  
  513. (defvar texinfo-end-of-header "%**end"
  514.   "String to mark end of header for texinfo-tex-region.")
  515.  
  516.  
  517. ;;; Insert string commands
  518.  
  519. (defconst texinfo-environment-regexp
  520.   "^@\\(f?table\\|enumerate\\|itemize\\|ifinfo\\|iftex\\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\\|flushleft\\|flushright\\|ignore\\|group\\|tex\\)"
  521.   "Regexp for environment-like TexInfo list commands.
  522. Subexpression 1 is what goes into the corresponding `@end' statement.")
  523.  
  524. ;; The following texinfo-insert-@end command not only inserts a SPC
  525. ;; after the @end, but tries to find out what belongs there.  It is
  526. ;; not very smart: it does not understand nested lists.
  527.  
  528. (defun texinfo-insert-@end ()
  529.   "Insert the matching `@end' for a @table etc. in a texinfo buffer.
  530. BUG: Does not understand nested lists."
  531.   (interactive)
  532.   (let ((string (save-excursion
  533.         (if (re-search-backward
  534.              texinfo-environment-regexp nil t) 
  535.             (buffer-substring (match-beginning 1)
  536.                       (match-end 1))))))
  537.     (insert "@end ")
  538.     (if string (insert string))))
  539.  
  540. ; Earlier version of texinfo-insert-@end
  541. ; (defun texinfo-insert-@end ()
  542. ;   "Insert the string `@end ' (end followed by a space) in a texinfo buffer."
  543. ;   (interactive)
  544. ;   (insert "@end "))
  545.  
  546. ;; The following insert commands accept a prefix arg N, which is the
  547. ;; number of words (actually s-exprs) that should be surrounded by
  548. ;; braces.  Thus you can first paste a variable name into a .texinfo
  549. ;; buffer, then say C-u 1 C-c C-c v at the beginning of the just
  550. ;; pasted variable name to put @var{...} *around* the variable name.
  551. ;; Operate on previous word or words with negative arg.
  552.  
  553. ;; These commands use texinfo-insert-@-with-arg
  554. (defun texinfo-insert-@-with-arg (string &optional arg)
  555.   (if arg 
  556.       (progn
  557.     (setq arg (prefix-numeric-value arg))
  558.     (if (< arg 0)
  559.         (progn
  560.           (skip-chars-backward " \t\n\r\f")
  561.           (save-excursion
  562.         (forward-sexp arg)
  563.         (insert "@" string "{"))
  564.           (insert "}"))
  565.       (skip-chars-forward " \t\n\r\f")
  566.       (insert "@" string "{")
  567.       (forward-sexp arg)
  568.       (insert "}")))
  569.     (insert "@" string "{}")
  570.     (backward-char)))
  571.  
  572. (defun texinfo-insert-braces ()
  573.   "Make a pair of braces and be poised to type inside of them.
  574. Use \\[up-list] to move forward out of the braces."
  575.   (interactive)
  576.   (insert "{}")
  577.   (backward-char))
  578.  
  579. ; (defun texinfo-insert-@code ()
  580. ;   "Insert the string @code in a texinfo buffer."
  581. ;   (interactive)
  582. ;   (insert "@code{}")
  583. ;   (backward-char))
  584.  
  585. (defun texinfo-insert-@code (&optional arg)
  586.   "Insert the string @code in a texinfo buffer."
  587.   (interactive "P")
  588.   (texinfo-insert-@-with-arg "code" arg))
  589.  
  590. ; (defun texinfo-insert-@dfn ()
  591. ;   "Insert the string @dfn in a texinfo buffer."
  592. ;   (interactive)
  593. ;   (insert "@dfn{}")
  594. ;   (backward-char))
  595.  
  596. (defun texinfo-insert-@dfn (&optional arg)
  597.   "Insert the string @dfn in a texinfo buffer."
  598.   (interactive "P")
  599.   (texinfo-insert-@-with-arg "dfn" arg))
  600.  
  601. (defun texinfo-insert-@example ()
  602.   "Insert the string @example in a texinfo buffer."
  603.   (interactive)
  604.   (insert "@example\n"))
  605.  
  606. (defun texinfo-insert-@file (&optional arg)
  607.   "Insert the string @file in a texinfo buffer."
  608.   (interactive "P")
  609.   (texinfo-insert-@-with-arg "file" arg))
  610.  
  611. ; (defun texinfo-insert-@item ()
  612. ;   "Insert the string @item in a texinfo buffer."
  613. ;   (interactive)
  614. ;   (insert "@item")
  615. ;   (newline))
  616.  
  617. (defun texinfo-insert-@item ()
  618.   "Insert the string @item in a texinfo buffer."
  619.   (interactive)
  620.   (insert "@item")
  621.   (newline))
  622.  
  623. ; (defun texinfo-insert-@kbd ()
  624. ;   "Insert the string @kbd in a texinfo buffer."
  625. ;   (interactive)
  626. ;   (insert "@kbd{}")
  627. ;   (backward-char))
  628.  
  629. (defun texinfo-insert-@kbd (&optional arg)
  630.   "Insert the string @kbd in a texinfo buffer."
  631.   (interactive "P")
  632.   (texinfo-insert-@-with-arg "kbd" arg))
  633.  
  634. ; (defun texinfo-insert-@node ()
  635. ;   "Insert the string @node in a texinfo buffer, 
  636. ; along with a comment indicating the arguments to @node."
  637. ;   (interactive)
  638. ;   (insert "@node \n@comment  node-name,  next,  previous,  up")
  639. ;   (forward-line -1)
  640. ;   (forward-char 6))
  641.  
  642. (defun texinfo-insert-@node ()
  643.   "Insert the string @node in a texinfo buffer, 
  644. along with a comment indicating the arguments to @node."
  645.   (interactive)
  646.   (insert "@node \n@comment  node-name,  next,  previous,  up")
  647.   (forward-line -1)
  648.   (forward-char 6))
  649.  
  650. ; (defun texinfo-insert-@noindent ()
  651. ;   "Insert the string @noindent in a texinfo buffer."
  652. ;   (interactive)
  653. ;   (insert "@noindent\n"))
  654.  
  655. (defun texinfo-insert-@noindent ()
  656.   "Insert the string @noindent in a texinfo buffer."
  657.   (interactive)
  658.   (insert "@noindent\n"))
  659.  
  660. ; (defun texinfo-insert-@samp ()
  661. ;   "Insert the string @samp in a texinfo buffer."
  662. ;   (interactive)
  663. ;   (insert "@samp{}")
  664. ;   (backward-char))
  665.  
  666. (defun texinfo-insert-@samp (&optional arg)
  667.   "Insert the string @samp in a texinfo buffer."
  668.   (interactive "P")
  669.   (texinfo-insert-@-with-arg "samp" arg))
  670.  
  671. (defun texinfo-insert-@table (&optional arg)
  672.   "Insert the string @table in a texinfo buffer."
  673.   (interactive "P")
  674.   (insert "@table "))
  675.  
  676. ; (defun texinfo-insert-@var ()
  677. ;   "Insert the string @var in a texinfo buffer."
  678. ;   (interactive)
  679. ;   (insert "@var{}")
  680. ;   (backward-char))
  681.  
  682. (defun texinfo-insert-@var (&optional arg)
  683.   "Insert the string @var in a texinfo buffer."
  684.   (interactive "P")
  685.   (texinfo-insert-@-with-arg "var" arg))
  686.  
  687.  
  688. ;;; Texinfo file structure
  689.  
  690. ; The following is defined in `texnfo-upd.el'
  691. ; (defvar texinfo-section-types-regexp
  692. ;   "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
  693. ;   "Regexp matching chapter, section, other headings (but not the top node).")
  694.  
  695. (defun texinfo-show-structure (&optional nodes-too) 
  696.   "Show the structure of a Texinfo file.
  697. List the lines in the file that begin with the @-sign commands for
  698. @chapter, @section, and the like.
  699.  
  700. With optional argument (prefix if interactive), list both the lines
  701. with @-sign commands for @chapter, @section, and the like, and list
  702. @node lines.
  703.  
  704. Lines with structuring commands beginning in them are displayed in
  705. another window called the *Occur* window.  In that window, you can
  706. position the cursor over one of the lines and use
  707. \\[occur-mode-goto-occurrence], 
  708. to jump to the corresponding spot in the Texinfo file."
  709.  
  710.   (interactive "P")
  711.   (require 'texnfo-upd)
  712.   (save-excursion 
  713.     (goto-char (point-min))
  714.     (if nodes-too
  715.         (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
  716.       (occur texinfo-section-types-regexp)))
  717.   (pop-to-buffer "*Occur*")
  718.   (goto-char (point-min))
  719.   (flush-lines "-----"))
  720.  
  721.  
  722. ;;; Place provide at end of file.
  723. (provide 'texinfo)
  724. ;;;;;;;;;;;;;;;; end texinfo.el ;;;;;;;;;;;;;;;;
  725.